<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>博客登录页</title>
    <link rel="stylesheet" href="./css/normal.css">
    <link rel="stylesheet" href="./css/login.css">
</head>

<body>
    <div class="nav">
        <img src="./pic/dog.png" alt="">
        <span class="blog_title">我的博客系统</span>
        <span class="space"></span>
        <a href="./blog_list.html" class="nav_span">主页</a>
        <a href="./edit.html" class="nav_span">写博客</a>
        <a href="reg.html" class="nav_span">注册</a>


    </div>


    <div class="login">

            <div class="dialog" style="height: 250px;">
                <h3>登录</h3>
                <div class="row">
                    <span>用户名</span>
                    <input type="text" name="name" id="username">
                </div>
                <div class="row">
                    <span>密码</span>
                    <input type="password" name="password" id="password">
                </div>
                
                <div class="row">
                    <button type="submit" id="submit" onclick="submit()" >提交</button>
                   
                </div>
                <div class="row">
                    <button type="submit" id="submit" onclick="reg()" >注册</button>
                </div>
            </div>

    </div>

    <script src="js/jquery-3.3.1.min.js"></script>
    <script>
        function submit(){
            var username = $("#username");
            var password = $("#password");
            // 非空校验
            if(username.val()==""){
                alert("请输入用户名！")
                username.focus();
                return;
            }
            if(password.val()==""){
                alert("请输入密码！")
                password.focus();
                return;
            }
            // 请求
            $.ajax({
                url:"/user/login",
                type:"POST",
                data:{ "userName":username.val(), "password":password.val()},
                success:function(result){
                    if(result!=null && result.code==200 && result.data!= null){
                        location.href="blog_list.html";
                    }else{
                        alert("抱歉，登录失败！用户名或密码输入错误，请重试！")
                    }
                }                
            })
        }
        function reg(){
            location.href="reg.html";
        }
    </script>
</body>

</html>